package com.feiyu.admin.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.feiyu.admin.entity.UserEntity;
import com.feiyu.admin.service.UserService;
import com.feiyu.common.utils.PageUtils;
import com.feiyu.common.utils.R;


/**
 * @author wanghanbin
 * @email 1336891708@qq.com
 * @date 2021-04-08 22:35:19
 */
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 增设管理员
     */
    @RequestMapping("/addAdmin")
    public R addAdmin(@RequestBody UserEntity user) {
        if ((userService.getByUserName(user.getUserName())) == null) {
            userService.save(user);
        } else {
            return R.error(4011, "用户名重复").put("data", null);
        }
        return R.ok("成功").put("data", null);
    }

    /**
     * 停用/启用账号
     */
    @RequestMapping("/switchUser")
    public R switchUser(@RequestBody UserEntity user) {
        userService.updateById(user);
        return R.ok("成功").put("data", null);
    }
}
